// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import './style/index.scss'

Vue.config.productionTip = false

// 全局路由守卫
router.beforeEach((to, from, next) => {
  var token = localStorage.getItem('mytoken')
  // 1.判断是否有token
  // 2.如果有直接进入下一页
  // 3.如果没有则跳转到/login
  // 4.如果是直接跳转到/login的，直接跳转到登录页面
  if (token) {
    next()
  } else {
    if (to.path === '/login') {
      next()
    } else {
      next({path: '/login'})
    }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
